import { http } from "../../utils/http";

//获取列表数据
export const getChannels = () => {
  return async dispatch => {
    const data = await http.get("channels");

    dispatch({ type: "article/setChannels", payload: data.data.channels });
  };
};
//获取表格数据
export const getArticles = (params) => {
  return async dispatch => {
    const data = await http.get("mp/articles", { params });
    dispatch({ type: "article/setArticles", payload: data });
  };
};

//删除逻辑
export const delArticle=id=>{
    return async dispatch=>{
        await http.delete(`mp/articles/${id}`)
    }
}

//添加文章
export const addArticle = (data, draft = false) => {
  return async dispatch => {
    await http.post(`mp/articles?draft=${false}`, data)
  }
}
//修改文章
export const editArticle = (data, draft=false) => {
  return async dispatch => {
    await http.put(`mp/articles/${data.id}?draft=${draft}`, data)
  }
}

//回显文章
export const getArticle = id => {
  return async dispatch => {
    const data = await http.get('mp/articles/' + id)
    
    return data.data
  }
}